package com.ushine.web.template.lock.controller;

import com.ushine.web.component.exception.ServiceException;
import com.ushine.web.component.http.HttpResponseVO;
import com.ushine.web.template.lock.facade.ILockServiceFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: yls
 * @Date 2022/4/7 10:11
 * @Description: 锁Lock测试控制器
 * @Version 1.0
 **/
@RestController
@Api(tags = "组件模块-锁Lock测试")
@RequestMapping("component/lock")
public class LockController {

    @Resource
    private ILockServiceFacade lockServiceFacade;

    @ApiOperation(value = "添加数值")
    @PostMapping("add")
    public HttpResponseVO<Object> addNumber() throws ServiceException {
        lockServiceFacade.addByThread(1);
        return new HttpResponseVO<>().ok("操作成功");
    }

    @ApiOperation(value = "减少数值")
    @PostMapping("decrease")
    public HttpResponseVO<Object> decreaseNumber() throws ServiceException {
        lockServiceFacade.decreaseByThread(1);
        return new HttpResponseVO<>().ok("操作成功");
    }
}
